package cn.bdqn.brand.controller;

import cn.bdqn.brand.pojo.Brand;
import cn.bdqn.brand.service.BrandService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SelectBrandServlet",urlPatterns = "/SelectBrandServlet")
public class SelectBrandServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 编码格式
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String brandId = request.getParameter("brandId");
        int id = Integer.parseInt(brandId);

        BrandService brandService = new BrandService();

        Brand brand = brandService.showAllBrand(id);

        // 序列化
        String jsonData = JSON.toJSONString(brand);

        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(jsonData);
    }
}
